﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Windows.Forms;
using Autodesk.Revit.DB;
using Autodesk.Revit.DB.ExtensibleStorage;
using Autodesk.Revit.UI;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.Plumbing.Properties;
using YArchitech.Revit;

namespace YArchitech.Plumbing
{
	public partial class SprayCalDialog : System.Windows.Forms.Form
	{
		private event HighLightElementHandler highEvent;

		public SprayCalDialog(Autodesk.Revit.DB.Document doc, UIDocument uiDoc, HYSystemCal hySystemCal)
		{
			this.InitializeComponent();
			new YJKProcessTools().ShowInTaskbarChange(this);
			base.Icon = (base.Icon = Resource.YArchitechIcon);
			this.hySystemCal = hySystemCal;
			this.doc = doc;
			this.uiDoc = uiDoc;
			this.hyTwinkle = new HYTwinkle();
			this.hyTwinkle.View = uiDoc.ActiveView;
			this.highEvent += this.OnHighLightElement;
		}

		private void MainForm_Load(object sender, EventArgs e)
		{
			this.cmbPipeDN.SelectedIndexChanged += this.cmbSelectedIndexChanged;
			this.cmbPipeDN.TextChanged += this.cmbTextChanged;
			this.cmbPipeDN.LostFocus += this.cmbLostFocus;
			this.listViewResult.Controls.Add(this.cmbPipeDN);
			this.cmbPipeDN.Visible = false;
			this.toolStripbtnCheckCal.Enabled = false;
			ProjectInfo projectInformation = this.doc.ProjectInformation;
			Schema schema = null;
			foreach (Guid guid in projectInformation.GetEntitySchemaGuids())
			{
				Schema schema2 = Schema.Lookup(guid);
				if (schema2.SchemaName == "BuildingInfo")
				{
					schema = schema2;
					break;
				}
			}
			if (schema != null)
			{
				string text = projectInformation.GetEntity(schema).Get<string>(schema.GetField("DangerLevel"));
				if (text != null)
				{
					this.dangerLevel = text;
				}
			}
			this.UpdateList();
			if (this.hySystemCal.GetCalculatedPipesForSpray().Count < 1 && !this.beMinimize)
			{
				YJKMessageBox.Information("没有需要计算的管道！");
				return;
			}
		}

		public void UpdateList()
		{
			this.listViewResult.Items.Clear();
			List<HYPipeCal> calculatedPipesForSpray = this.hySystemCal.GetCalculatedPipesForSpray();
			int num = 1;
			bool enabled = false;
			foreach (HYPipeCal hypipeCal in calculatedPipesForSpray)
			{
				if (hypipeCal.endSprinkler == null)
				{
					ListViewItem listViewItem = new ListViewItem();
					hypipeCal.Number = string.Format("F-{0}", num);
					num++;
					listViewItem.Text = hypipeCal.Number.ToString();
					listViewItem.Tag = hypipeCal;
					ListViewItem.ListViewSubItem listViewSubItem = new ListViewItem.ListViewSubItem();
					double num2 = 0.0;
					if (hypipeCal.endNode != null)
					{
						num2 = hypipeCal.endNode.Pressure;
					}
					listViewSubItem.Text = num2.ToString("f2");
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = hypipeCal.Length.ToString("f3");
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Name = "PipeDN";
					listViewSubItem.Text = hypipeCal.nDN.ToString("");
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = hypipeCal.dEquivalent.ToString("f2");
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = hypipeCal.Velocity.ToString("f2");
					if (hypipeCal.Velocity >= 5.0)
					{
						listViewSubItem.Tag = hypipeCal.Velocity;
						enabled = true;
					}
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = hypipeCal.Flow.ToString("f2");
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					listViewSubItem.Text = (hypipeCal.LossAll * 100.0).ToString("f2");
					listViewItem.SubItems.Add(listViewSubItem);
					listViewSubItem = new ListViewItem.ListViewSubItem();
					double num3 = 0.0;
					if (hypipeCal.startNode != null)
					{
						num3 = hypipeCal.startNode.Pressure;
					}
					listViewSubItem.Text = num3.ToString("f2");
					listViewItem.SubItems.Add(listViewSubItem);
					this.listViewResult.Items.Add(listViewItem);
				}
			}
			this.listViewResult.Refresh();
			this.toolStripbtnCheckCal.Enabled = enabled;
		}

		protected ExcelData GetExcelData()
		{
			List<ExcelData.Cell> list = new List<ExcelData.Cell>();
			List<List<ExcelData.Cell>> list2 = new List<List<ExcelData.Cell>>();
			string text = null;
			for (int i = 0; i < this.listViewResult.Columns.Count; i++)
			{
				list.Add(new ExcelData.Cell
				{
					TypeOfCell = ExcelData.ExcelCellType.StringCell,
					Data = this.listViewResult.Columns[i].Text
				});
			}
			ExcelData.Cell cell;
			for (int j = 0; j < this.listViewResult.Items.Count; j++)
			{
				List<ExcelData.Cell> list3 = new List<ExcelData.Cell>();
				list3.Add(new ExcelData.Cell
				{
					TypeOfCell = ExcelData.ExcelCellType.StringCell,
					Data = this.listViewResult.Items[j].SubItems[0].Text
				});
				text = this.listViewResult.Items[j].SubItems[1].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 2;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[2].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 3;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[3].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.Int32Cell;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[4].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 2;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[5].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 2;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[6].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 2;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[7].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 3;
				}
				cell.Data = text;
				list3.Add(cell);
				text = this.listViewResult.Items[j].SubItems[8].Text;
				cell = new ExcelData.Cell();
				if (string.IsNullOrEmpty(text))
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
				}
				else
				{
					cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
					cell.Round = 3;
				}
				cell.Data = text;
				list3.Add(cell);
				list2.Add(list3);
			}
			ExcelData excelData = new ExcelData();
			excelData.SheetName = "喷淋系统水力计算表";
			excelData.FileName = "喷淋系统水力计算表";
			excelData.Title = "喷淋系统水力计算表";
			excelData.ColumnsData = list;
			excelData.RowsData = list2;
			List<List<ExcelData.Cell>> list4 = new List<List<ExcelData.Cell>>();
			string data = string.Empty;
			string data2 = string.Empty;
			string data3 = string.Empty;
			CalculateType calculateType = this.calType;
			if (calculateType != CalculateType.CalByCheckTheFirst)
			{
				if (calculateType != CalculateType.CalBycheckTheWorst)
				{
					data = "最不利喷头";
					data2 = "最不利喷头压力（m·H20)";
				}
				else
				{
					data = "入口压力";
					data2 = "入口压力（m·H20）";
				}
			}
			else
			{
				data = "最不利喷头";
				data2 = "最不利喷头压力（m·H20)";
			}
			list4.Add(new List<ExcelData.Cell>
			{
				new ExcelData.Cell
				{
					TypeOfCell = ExcelData.ExcelCellType.StringCell,
					Data = "计算类型"
				},
				new ExcelData.Cell
				{
					TypeOfCell = ExcelData.ExcelCellType.StringCell,
					Data = data
				}
			});
			list4.Add(new List<ExcelData.Cell>
			{
				new ExcelData.Cell
				{
					TypeOfCell = ExcelData.ExcelCellType.StringCell,
					Data = "危险等级"
				},
				new ExcelData.Cell
				{
					TypeOfCell = ExcelData.ExcelCellType.StringCell,
					Data = this.dangerLevel
				}
			});
			List<ExcelData.Cell> list5 = new List<ExcelData.Cell>();
			list5.Add(new ExcelData.Cell
			{
				TypeOfCell = ExcelData.ExcelCellType.StringCell,
				Data = data2
			});
			cell = new ExcelData.Cell();
			data3 = this.dworstPressure.ToString("f2");
			if (string.IsNullOrEmpty(text))
			{
				cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
			}
			else
			{
				cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
				cell.Round = 2;
			}
			cell.Data = data3;
			list5.Add(cell);
			list4.Add(list5);
			List<ExcelData.Cell> list6 = new List<ExcelData.Cell>();
			list6.Add(new ExcelData.Cell
			{
				TypeOfCell = ExcelData.ExcelCellType.StringCell,
				Data = "同时作用面积（m²）"
			});
			cell = new ExcelData.Cell();
			data3 = this.deffectArea.ToString("f2");
			if (string.IsNullOrEmpty(text))
			{
				cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
			}
			else
			{
				cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
				cell.Round = 2;
			}
			cell.Data = data3;
			list6.Add(cell);
			list4.Add(list6);
			List<ExcelData.Cell> list7 = new List<ExcelData.Cell>();
			list7.Add(new ExcelData.Cell
			{
				TypeOfCell = ExcelData.ExcelCellType.StringCell,
				Data = "特性系数K"
			});
			cell = new ExcelData.Cell();
			data3 = this.coefficientK.ToString("f0");
			if (string.IsNullOrEmpty(text))
			{
				cell.TypeOfCell = ExcelData.ExcelCellType.StringCell;
			}
			else
			{
				cell.TypeOfCell = ExcelData.ExcelCellType.doubleCell;
				cell.Round = 0;
			}
			cell.Data = data3;
			list7.Add(cell);
			list4.Add(list7);
			excelData.ForwardData = list4;
			excelData.BackwardData = "计算结果： " + this.resultText.Text.Replace("\n", "");
			return excelData;
		}

		protected override void WndProc(ref Message m)
		{
			try
			{
				if (m.WParam.ToInt32() == 61472)
				{
					this.beMinimize = true;
					if (this.hyTwinkle != null)
					{
						this.hyTwinkle.Stop();
						this.elemIds = new List<ElementId>();
						for (int i = 0; i < this.listViewResult.SelectedItems.Count; i++)
						{
							HYPipeCal hypipeCal = this.listViewResult.SelectedItems[i].Tag as HYPipeCal;
							if (hypipeCal != null)
							{
								ElementId elementId = new ElementId(hypipeCal.Id);
								if (this.doc.GetElementById(elementId) != null)
								{
									this.elemIds.Add(elementId);
								}
							}
						}
						base.DialogResult = DialogResult.Abort;
					}
				}
				else
				{
					base.WndProc(ref m);
				}
			}
			catch (Exception)
			{
			}
		}

		private void StopTwinkle()
		{
			this.hyTwinkle.Stop();
		}

		private void OnHighLightElement(object sender, ElementEventArgs e)
		{
			if (this.hyTwinkle == null)
			{
				return;
			}
			this.hyTwinkle.Stop();
			ElementId elementId = new ElementId(e.ElementId);
			List<ElementId> list = new List<ElementId>();
			if (this.doc.GetElementById(elementId) != null)
			{
				list.Add(elementId);
				this.hyTwinkle.Ids = list;
				this.hyTwinkle.Start();
			}
		}

		private void listViewResult_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
		{
			this.elemIds = new List<ElementId>();
			if (e.IsSelected)
			{
				HYPipeCal hypipeCal = e.Item.Tag as HYPipeCal;
				if (hypipeCal != null)
				{
					ElementId elementId = new ElementId(hypipeCal.Id);
					this.highEvent(this, new ElementEventArgs(elementId.IntegerValue));
					if (this.doc.GetElementById(elementId) != null)
					{
						this.elemIds.Add(elementId);
					}
				}
			}
		}

		private void cmbLostFocus(object sender, EventArgs e)
		{
			this.cmbPipeDN.Visible = false;
			this.listViewResult.Invalidate(true);
		}

		private void cmbTextChanged(object sender, EventArgs e)
		{
			if (this.selectedSubItem != null)
			{
				this.selectedSubItem.Text = ((System.Windows.Forms.ComboBox)sender).Text;
			}
		}

		private void cmbSelectedIndexChanged(object sender, EventArgs e)
		{
			if (this.selectedSubItem != null)
			{
				this.selectedSubItem.Text = ((System.Windows.Forms.ComboBox)sender).Text;
			}
		}

		private void BindingComboBoxInfo(List<string> ItemContants, bool bEdit = false)
		{
			if (this.cmbPipeDN == null)
			{
				this.cmbPipeDN = new System.Windows.Forms.ComboBox();
			}
			DataTable dataTable = new DataTable();
			dataTable.Columns.Add("Value");
			dataTable.Columns.Add("Contants");
			for (int i = 0; i < ItemContants.Count; i++)
			{
				DataRow dataRow = dataTable.NewRow();
				dataRow[0] = i;
				dataRow[1] = ItemContants[i];
				dataTable.Rows.Add(dataRow);
			}
			this.cmbPipeDN.ValueMember = "Value";
			this.cmbPipeDN.DisplayMember = "Contants";
			this.cmbPipeDN.DataSource = dataTable;
			if (bEdit)
			{
				this.cmbPipeDN.DropDownStyle = ComboBoxStyle.DropDown;
				return;
			}
			this.cmbPipeDN.DropDownStyle = ComboBoxStyle.DropDownList;
		}

		private string GetCloserNum(string sNum, List<double> snewNums)
		{
			if (snewNums.Count == 0)
			{
				return null;
			}
			int num = (int)short.Parse(sNum);
			double num2 = snewNums[0];
			double num3 = Math.Abs((double)num - num2);
			for (int i = 0; i < snewNums.Count; i++)
			{
				if (Math.Abs((double)num - snewNums[i]) <= num3)
				{
					num3 = Math.Abs((double)num - snewNums[i]);
					if (num2 < snewNums[i])
					{
						num2 = snewNums[i];
					}
				}
			}
			return num2.ToString();
		}

		private void ProcessCombobox(MouseEventArgs e)
		{
			ListViewHitTestInfo listViewHitTestInfo = this.listViewResult.HitTest(e.X, e.Y);
			this.selectedSubItem = listViewHitTestInfo.SubItem;
			if (this.selectedSubItem != null && this.selectedSubItem.Name == "PipeDN")
			{
				HYPipeCal hypipeCal = listViewHitTestInfo.Item.Tag as HYPipeCal;
				if (hypipeCal != null)
				{
					List<string> list = new List<string>();
					List<double> list2 = new List<double>();
					foreach (KeyValuePair<int, double> keyValuePair in hypipeCal.dirDNArray)
					{
						list.Add(keyValuePair.Key.ToString());
						list2.Add((double)keyValuePair.Key);
					}
					string closerNum = this.GetCloserNum(this.selectedSubItem.Text, list2);
					this.BindingComboBoxInfo(list, false);
					this.cmbPipeDN.Text = closerNum;
					this.cmbPipeDN.Left = this.selectedSubItem.Bounds.Left;
					this.cmbPipeDN.Top = this.selectedSubItem.Bounds.Top;
					this.cmbPipeDN.Width = this.selectedSubItem.Bounds.Width;
					this.cmbPipeDN.Height = this.selectedSubItem.Bounds.Height;
					this.cmbPipeDN.Visible = true;
					return;
				}
			}
			else
			{
				this.selectedSubItem = null;
				this.cmbPipeDN.Visible = false;
			}
		}

		private void listViewResult_MouseClick(object sender, MouseEventArgs e)
		{
			this.ProcessCombobox(e);
		}

		private void listViewResult_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			this.ProcessCombobox(e);
		}

		private void listViewResult_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
		{
			e.DrawBackground();
			e.DrawText(TextFormatFlags.VerticalCenter);
		}

		private void listViewResult_DrawItem(object sender, DrawListViewItemEventArgs e)
		{
			if ((e.State & ListViewItemStates.Selected) != (ListViewItemStates)0)
			{
				e.Graphics.FillRectangle(Brushes.Yellow, e.Bounds);
				e.DrawFocusRectangle();
				return;
			}
			e.DrawBackground();
		}

		private void listViewResult_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
		{
			if (e.SubItem.Name == "PipeDN")
			{
				e.Graphics.FillRectangle(Brushes.LightGreen, e.Bounds);
				e.DrawFocusRectangle(e.Bounds);
			}
			if (e.SubItem.Tag != null)
			{
				e.Graphics.FillRectangle(Brushes.Pink, e.Bounds);
				e.DrawFocusRectangle(e.Bounds);
			}
			e.DrawText();
		}

		private bool checkInputData()
		{
			bool result = true;
			if (this.dParticalLoss == 0.0 || this.dworstPressure == 0.0)
			{
				result = false;
			}
			return result;
		}

		protected override void OnClosed(EventArgs e)
		{
			base.OnClosed(e);
			if (this.hyTwinkle != null)
			{
				this.hyTwinkle.Dispose();
			}
		}

		private void UpdataDataFormDataView()
		{
			List<HYPipeCal> list = new List<HYPipeCal>();
			int num = -1;
			for (int i = 0; i < this.listViewResult.Items.Count; i++)
			{
				if (num < 0)
				{
					for (int j = 0; j < this.listViewResult.Items[i].SubItems.Count; j++)
					{
						if (this.listViewResult.Items[i].SubItems[j].Name == "PipeDN")
						{
							num = j;
							break;
						}
					}
				}
				HYPipeCal hypipeCal = this.listViewResult.Items[i].Tag as HYPipeCal;
				hypipeCal.nDN = int.Parse(this.listViewResult.Items[i].SubItems[num].Text);
				list.Add(hypipeCal);
			}
			using (List<HYPipeCal>.Enumerator enumerator = list.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					HYPipeCal item = enumerator.Current;
					if (this.hySystemCal.PipeCals.Exists((HYPipeCal q) => q.Id == item.Id))
					{
						this.hySystemCal.PipeCals.First((HYPipeCal q) => q.Id == item.Id).nDN = item.nDN;
					}
				}
			}
		}

		private void toolStripbtnFetchData_Click(object sender, EventArgs e)
		{
			this.hySystemCal.ResetPipeInfo();
			this.bIsCalculated = false;
			this.resultText.Text = "";
			base.DialogResult = DialogResult.Abort;
			this.beMinimize = false;
			this.toolStripbtnCheckCal.Enabled = false;
		}

		private void toolStripbtnReturnGraph_Click(object sender, EventArgs e)
		{
			if (this.bIsCalculated)
			{
				this.UpdataDataFormDataView();
				base.DialogResult = DialogResult.OK;
				return;
			}
			YJKMessageBox.Information("还没有进行计算，计算以后才能赋回图面");
		}

		private void toolStripbtnParaSetting_Click(object sender, EventArgs e)
		{
			SprayCalculatePara sprayCalculatePara = new SprayCalculatePara();
			sprayCalculatePara.CalTypePara = this.calType;
			sprayCalculatePara.ParticalLossPara = this.dParticalLoss;
			sprayCalculatePara.WorstPressurePara = this.dworstPressure;
			sprayCalculatePara.EffectAreaPara = this.deffectArea;
			sprayCalculatePara.CoefficientK = this.coefficientK;
			sprayCalculatePara.DangerLevelPara = this.dangerLevel;
			if (sprayCalculatePara.ShowDialog() == DialogResult.OK)
			{
				this.calType = sprayCalculatePara.CalTypePara;
				this.dParticalLoss = sprayCalculatePara.ParticalLossPara;
				this.dworstPressure = sprayCalculatePara.WorstPressurePara;
				this.deffectArea = sprayCalculatePara.EffectAreaPara;
				this.coefficientK = sprayCalculatePara.CoefficientK;
				this.dangerLevel = sprayCalculatePara.DangerLevelPara;
			}
		}

		private void toolStripbtnCalculate_Click(object sender, EventArgs e)
		{
			this.Calculation(0);
		}

		private void toolStripbtnCheckCal_Click(object sender, EventArgs e)
		{
			AdjustPipeDN adjustPipeDN = new AdjustPipeDN();
			if (adjustPipeDN.ShowDialog() == DialogResult.OK)
			{
				if (adjustPipeDN.bFinnalyCheck)
				{
					this.Calculation(2);
					return;
				}
				this.Calculation(1);
			}
		}

		private bool Calculation(int checkOption = 0)
		{
			if (!this.checkInputData())
			{
				return false;
			}
			if (this.hySystemCal.GetCalculatedPipesForSpray().Count < 1)
			{
				YJKMessageBox.Information("没有需要计算的管道！");
				return false;
			}
			SprayCalculate sprayCalculate = new SprayCalculate(this.hySystemCal.SprayStartPipe, this.hySystemCal.SprayNodes);
			this.hySystemCal.ResetPipeInfo();
			sprayCalculate.CalType = this.calType;
			sprayCalculate.PartialLossFactor = this.dParticalLoss;
			sprayCalculate.FixedPressure = this.dworstPressure;
			sprayCalculate.EffectArea = this.deffectArea;
			sprayCalculate.SprinklerCoefficient = this.coefficientK;
			sprayCalculate.checkOption = checkOption;
			this.UpdataDataFormDataView();
			sprayCalculate.SetFixedPressure(this.calType, sprayCalculate.FixedPressure);
			bool flag = true;
			if (this.calType == CalculateType.CalByCheckTheFirst || this.calType == CalculateType.CalBycheckTheWorst)
			{
				flag = sprayCalculate.SolveAccumulateMethod();
			}
			this.UpdateList();
			if (flag)
			{
				this.resultText.Text = sprayCalculate.GetResult();
				this.bIsCalculated = true;
			}
			else
			{
				this.resultText.Text = "计算失败！";
			}
			return flag;
		}

		private void toolStripbtnWriteExcel_Click(object sender, EventArgs e)
		{
			try
			{
				ExcelData excelData = this.GetExcelData();
				if (excelData.RowsData.Count > 0)
				{
					new CalExportExcelProgressBar(this.hySystemCal, excelData).ShowDialog();
				}
				else
				{
					YJKMessageBox.Information("没有数据需要导出！");
				}
			}
			catch (Exception ex)
			{
				YJKMessageBox.Error(ex.ToString());
			}
		}

		private void toolStripbtnExit_Click(object sender, EventArgs e)
		{
			base.DialogResult = DialogResult.Cancel;
		}

		private void listViewResult_MouseMove(object sender, MouseEventArgs e)
		{
			this.listViewResult.Invalidate();
		}

		private void listViewResult_MouseWheel(object sender, EventArgs e)
		{
			this.listViewResult.Invalidate();
		}

		private void listViewResult_MouseWheel(object sender, MouseEventArgs e)
		{
		}

		public HYSystemCal hySystemCal;

		private Document doc;

		private UIDocument uiDoc;

		private CalculateType calType;

		private double dParticalLoss = 0.2;

		private double dworstPressure = 5.0;

		public double deffectArea;

		public double coefficientK = 80.0;

		private string dangerLevel = "中危险等级II";

		private bool bIsCalculated;

		public List<ElementId> elemIds;

		public bool beMinimize;

		private HYTwinkle hyTwinkle;

		private const int SC_MINIMIZE = 61472;

		private System.Windows.Forms.ComboBox cmbPipeDN = new System.Windows.Forms.ComboBox();

		private const string DNSubItemName = "PipeDN";

		private ListViewItem.ListViewSubItem selectedSubItem;

		private const double VelocityToCheck = 5.0;
	}
}
